﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

namespace OtechWebServer
{
    public partial class PostTaxiRoute : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
       
            string phoneNumber = "";
            DateTime startTime = new DateTime();
            DateTime endTime = new DateTime();
            double distance = 0;
            int state = 0;
            if (Request.QueryString["PhoneNumber"] != null &&
                Request.QueryString["StartTime"] != null &&
                Request.QueryString["EndTime"] != null &&
                Request.QueryString["Distance"] != null &&
                Request.QueryString["State"] != null)
            {
                phoneNumber = Request.QueryString["PhoneNumber"];
                startTime = DateTime.Parse(Request.QueryString["StartTime"]);
                endTime = DateTime.Parse(Request.QueryString["EndTime"]);
                distance = double.Parse(Request.QueryString["Distance"]);
                state = int.Parse(Request.QueryString["State"]);

                StringBuilder strSql = new StringBuilder();
                strSql.Append("insert into tTaxiRouteHistory(");
                strSql.Append("PhoneNumber,StartTime,EndTime,");
                strSql.Append("Distance,State,ServerTime)");
                strSql.Append(" values ('");
                strSql.Append(phoneNumber);
                strSql.Append("','");
                strSql.Append(startTime);
                strSql.Append("','");
                strSql.Append(endTime);
                strSql.Append("',");
                strSql.Append(distance);
                strSql.Append(",");
                strSql.Append(state);
                strSql.Append(",'");
                strSql.Append(DateTime.Now);
                strSql.Append("');");
                MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection();
                connection.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbconn"].ToString();
                using (MySqlCommand cmd = new MySqlCommand(strSql.ToString(), connection))
                {
                    try
                    {
                        connection.Open();
                        int rows = cmd.ExecuteNonQuery();
                        
                        Response.Write(rows);
                    }
                    catch (MySql.Data.MySqlClient.MySqlException ex)
                    {
                        Response.Write("-1");
                    }
                    finally
                    {
                        connection.Close();
                    }
                }

            }
            else
            {
                Response.Write("-1");
            } 
        
        }
    }
}